package com.egao.orderB.controller;

import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.*;
import com.egao.common.core.annotation.OperLog;
import com.egao.orderB.entity.ElectricFence;
import com.egao.orderB.service.ElectricFenceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.ui.Model;


/**
 *
 * 电子围栏
 * @author : Doman
 * @date : 2020-12-22 15:23:22
 * @version ：1.0
 */

@Api(tags = "电子围栏")
@RestController
@RequestMapping("/api/orderB/electricFence")
public class ElectricFenceController extends BaseController {

	@Autowired
	private ElectricFenceService electricFenceService;

	/**
	 * 分页查询列表
	 */
	@PreAuthorize("hasAuthority('orderB:electricFence:list')")
    //@OperLog(value = "电子围栏", desc = "分页查询")
    @ApiOperation(value ="分页查询电子围栏",notes = "" +
       "id:id\n" +
       "name:名称\n" +
       "longitude:经度\n" +
       "latitude:纬度\n" +
       "radius:半径 默认米\n" +
       "type:类型: 堆场,工厂,港口\n" +
       "createTime:创建时间\n" +
       "createUser:创建人\n" +
       "updateTime:更新时间\n" +
       "updateUser:更新人\n" +
        "",httpMethod = "POST")
    @ApiPageParam
    @PostMapping("/list")
    public JsonResult page(PageResult2<T> page, ElectricFence electricFence) throws Exception{
        return electricFenceService.list(page, electricFence, getLoginUser());
    }

    /**
     * 查询全部电子围栏
     */
    @PreAuthorize("hasAuthority('orderB:electricFence:list')")
    //@OperLog(value = "电子围栏", desc = "查询全部")
    @ApiOperation("查询全部电子围栏")
    @PostMapping("/listAll")
    public JsonResult list(ElectricFence electricFence){
        return electricFenceService.list(electricFence, getLoginUser());
    }

    /**
     * 根据id查询电子围栏
     */
    @PreAuthorize("hasAuthority('orderB:electricFence:list')")
    //@OperLog(value = "电子围栏", desc = "根据id查询")
    @ApiOperation("根据id查询电子围栏")
    @PostMapping("/get")
    public JsonResult get(ElectricFence electricFence) {
        return electricFenceService.getById(electricFence);
		// 使用关联查询
        //PageParam<electricFence> pageParam = new PageParam<>();
		//pageParam.put("id", id);
        //List<electricFence> records = electricFenceService.listAll(pageParam.getNoPageParam());
        //return JsonResult.ok().setData(pageParam.getOne(records));
    }


    /**
     * 添加电子围栏
     */
    @PreAuthorize("hasAuthority('orderB:electricFence:save')")
    @OperLog(value = "电子围栏", desc = "添加", param = false, result = true)
    @ApiOperation(value ="添加电子围栏",notes = "" +
           "name:名称\n" +
           "longitude:经度\n" +
           "latitude:纬度\n" +
            "radius:半径 默认米\n" +
            "type:类型: 堆场,工厂,港口\n" +
        "",httpMethod = "POST")
    @PostMapping("/save")
    public JsonResult save(Model model, ElectricFence electricFence) {
        return electricFenceService.save(electricFence, getLoginUser());
    }

    /**
     * 修改电子围栏
     */
    @PreAuthorize("hasAuthority('orderB:electricFence:update')")
    @OperLog(value = "电子围栏", desc = "修改", param = false, result = true)
    @ApiOperation(value ="修改电子围栏",notes = "" +
           "id:id\n" +
           "name:名称\n" +
           "longitude:经度\n" +
           "latitude:纬度\n" +
            "radius:半径 默认米\n" +
            "type:类型: 堆场,工厂,港口\n" +
        "",httpMethod = "POST")
    @PostMapping("/update")
    public JsonResult update(Model model, ElectricFence electricFence) {
        return electricFenceService.update(electricFence, getLoginUser());
    }

    /**
     * 删除电子围栏
     */
    @PreAuthorize("hasAuthority('orderB:electricFence:remove')")
    @OperLog(value = "电子围栏", desc = "删除", result = true)
    @ApiOperation("删除电子围栏")
    @PostMapping("/remove")
    public JsonResult remove(ElectricFence electricFence ) {
        return electricFenceService.remove(electricFence, getLoginUser());
    }

    /**
     * 批量添加电子围栏
     */
    /**@RequiresPermissions("orderB:electricFence:save")
    @OperLog(value = "电子围栏", desc = "批量添加", param = false, result = true)
    @ResponseBody
    @PostMapping("/saveBatch")
    public JsonResult saveBatch(@RequestBody List<ElectricFence> list) {
        if (electricFenceService.saveBatch(list)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }*/

    /**
     * 批量修改电子围栏
     */
    /**@RequiresPermissions("orderB:electricFence:update")
    @OperLog(value = "电子围栏", desc = "批量修改", result = true)
    @ResponseBody
    @PostMapping("/updateBatch")
    public JsonResult updateBatch(@RequestBody BatchParam<ElectricFence> batchParam) {
        if (batchParam.update(electricFenceService, "")) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }*/

    /**
     * 批量删除电子围栏
     */
    /**@RequiresPermissions("orderB:electricFence:remove")
    @OperLog(value = "电子围栏", desc = "批量删除", result = true)
    @ResponseBody
    @PostMapping("/removeBatch")
    public JsonResult removeBatch(@RequestBody List<Integer> ids) {
        if (electricFenceService.removeByIds(ids)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }*/

}
